package cn.wolfcode.plus.util;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@Setter
@Getter
@NoArgsConstructor
@AllArgsConstructor
public class JsonResult {

    private int code;
    private String msg;
    private Object data;

    enum Type {
        SUCCESS(200),
        ERROR(500);

        private final int value;

        Type(int value) {
            this.value = value;
        }

        public int getValue() {
            return value;
        }
    }

    public static JsonResult success(String msg,Object obj) {
        return new JsonResult(Type.SUCCESS.value,msg,obj);
    }

    public static JsonResult success() {
        return new JsonResult(Type.SUCCESS.value,null,null);
    }

    public static JsonResult success(String msg) {
        return new JsonResult(Type.SUCCESS.value,msg,null);
    }

    public static JsonResult error(String msg,Object obj) {
        return new JsonResult(Type.ERROR.value,msg,obj);
    }

    public static JsonResult error() {
        return new JsonResult(Type.ERROR.value,null,null);
    }

    public static JsonResult error(String msg) {
        return new JsonResult(Type.ERROR.value,msg,null);
    }
}
